package hp.com.util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletCookie")
public class ServletCookie extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie[] cookies = req.getCookies();

        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if ("userCookieName".equals(cookie.getName())) {
                String value = cookie.getValue();
                req.setAttribute("userCookieName",value);
            }
            if ("userCookiePwd".equals(cookie.getName())) {
                String value = cookie.getValue();
                req.setAttribute("userCookiePwd",value);
            }
        }
        req.getRequestDispatcher("easybuy/Login.jsp").forward(req,resp);
    }
}
